// Never out of Now Replication File

// Requires installation of cem, grc1leg and coefplot

/* Load Sudan data (MI Set) */

use SUForPub, clear

/* generate missing variable indicators for democratic support and gradual change */

gen democraticMissing = .
replace democraticMissing =   1 if DemocraticSupport==.
replace democraticMissing =   0 if DemocraticSupport != . & imp==0

gen GovPMiss = 1 if GovPer==. & imp==0
replace GovPMiss = 0 if GovPer!=. & imp==0
gen GovDMiss = 1 if GovDoesAllItCan==. & imp==0
replace GovDMiss = 0 if GovDoesAllItCan!=. & imp==0
gen TrustGMiss = 1 if  TrustGov==. & imp==0
replace TrustGMiss = 0 if  TrustGov!=. & imp==0
gen GovCorrMiss = 1 if  GovCorruption==. & imp==0
replace GovCorrMiss = 0 if   GovCorruption!=. & imp==0
gen CritMissing =  GovPMiss + GovDMiss + TrustGMiss + GovCorrMiss
mi register regular democraticMissing CritMissing GovCorrMiss TrustGMiss GovDMiss GovPMiss

gen GovPerR2 = -1*GovPer + 1
gen TrustGovR2 = -1*TrustGov + 1
gen GovDoesAllR2 = -1*GovDoesAllItCan + 1
gen CritGov2= GovPerR2 + TrustGovR2 + GovDoesAllR2 + GovCorruption
mi register passive CritGov2 GovPerR2 TrustGovR2 GovDoesAllR2 

/* Figure 1: Sudan Government Performance (some aesthetic changes made in graph editor)*/

graph bar (mean) GovPer if imp==0, over(ArabSpring, relabel(1 "Before Tunisian Revolution" 2 "After Tunisian Revolution" )) asyvars bargap(10) bar(1, color(green*0.6)) bar(2, color(blue*0.5))  ytitle("Proportion Positive or Neutral") graphregion(color(white)) bgcolor(white) title("Evaluation of Government Performance in Sudan") saving(SBFigure1, asis replace)
graph export SBFigure1.png

/* Figure 2: Sudan Support for Government kernel density (graph done in R, but a kernel density function was drawn in Stata to simplify replication - See SBFigure2.R )*/

kdensity GovSatisfaction if imp==0, kernel(gaussian) nograph generate(x fx)
kdensity GovSatisfaction if ArabSpring==0 & imp==0, kernel(gaussian) nograph generate(fx0) at(x)
kdensity GovSatisfaction if ArabSpring==1 & imp==0, kernel(gaussian) nograph generate(fx1) at(x)
label var fx0 "Before Tunisian Revolution"
label var fx1 "After Tunisian Revolution"
line fx0 fx1 x, lwidth(medthick) sort ytitle("Denisty") title("Satisfaction with Government in Sudan") graphregion(color(white)) bgcolor(white) saving(SBFigure2Stata, asis replace)
graph export SBFigure2Stata.png
drop fx x fx0 fx1

/* Table 1: Covariate Balance (table created by hand) 
Sudan Coarsening -, Age (18-27, 28-37, 38-47, 48-57, 58-67, 68-77, 78+) */

imb Rural lnincome Age Female, tr(ArabSpring) impvar(imp)

summarize lnincome if imp==0, detail

cem Rural lnincome Age (0 27.5 37.5 47.5 57.5 67.5 77.5 110) Female, tr(ArabSpring) impvar(imp)

// Recode Provinces with few observations
replace  ProvinceName = 9010 if ProvinceName==9003
replace  ProvinceName = 9004 if ProvinceName==9012

save SudanCEM, replace
  

/* Figure 3, saved tables in appendix: Regression Analyses on Matched Data */
/* Sudan */  

/* The following code requires the coefplot package, which can be downloaded using:
ssc install coefplot, replace */

eststo Freeriding: mi estimate, post: reg Freeriding ArabSpring Rural Female lnincome Age i.ProvinceName [aweight=cem_weights], r

eststo CritGov: mi estimate, post: reg CritGov2 ArabSpring Rural Female lnincome Age i.ProvinceName [aweight=cem_weights], r

eststo CurrentEcon: mi estimate, post: reg CurrentEcon ArabSpring Rural Female lnincome Age i.ProvinceName [aweight=cem_weights], r

eststo FutureEcon: mi estimate, post: reg FutureEcon ArabSpring Rural Female lnincome Age i.ProvinceName [aweight=cem_weights], r

coefplot (Freeriding, lab(Social Capital)) (CritGov, lab(Criticize Government)) (CurrentEcon, lab(Current Economy)) (FutureEcon, lab(Future Economy)), keep(ArabSpring) mlabel yline(0) vert format(%9.2f) graphregion(color(white)) coeflabels(ArabSpring = "Sudan", notick ) bgcolor(white)  name(Sudan3) saving(SBf3Sudan, asis replace)

/* Used for actual paper coefplot (Freeriding, lab(Social Capital)) (GovPer, lab(Government Performance)) (TrustGov, lab(Trust Government)) Corruption (CurrentEcon, lab(Current Economy)) (FutureEcon, lab(Future Economy)) Democracy, keep(ArabSpring) mlabel yline(0) vert format(%9.2f) graphregion(color(white))  coeflabels(ArabSpring = "Lebanon", notick ) bgcolor(white) */
save, replace

/* Lebanon - Income below or above the median, Age (18-27, 28-37, 38-47, 48-57, 58-67, 68-77, 78+), Education No post-secondary education, post-secodary education */
use LForPub, clear

gen democraticMissing = .
replace democraticMissing =   1 if DemocraticSupport==.
replace democraticMissing =   0 if DemocraticSupport != . & imp==0

gen GovPMiss = 1 if GovPerLeb==. & imp==0
replace GovPMiss = 0 if GovPerLeb!=. & imp==0
gen GovDMiss = 1 if GovDoesAllItCan==. & imp==0
replace GovDMiss = 0 if GovDoesAllItCan!=. & imp==0
gen TrustGMiss = 1 if  TrustGov==. & imp==0
replace TrustGMiss = 0 if  TrustGov!=. & imp==0
gen GovCorrMiss = 1 if  GovCorruption==. & imp==0
replace GovCorrMiss = 0 if   GovCorruption!=. & imp==0
gen CritMissing =  GovPMiss + GovDMiss + TrustGMiss + GovCorrMiss
mi register regular democraticMissing CritMissing GovCorrMiss TrustGMiss GovDMiss GovPMiss

gen GovPerR2 = -1*GovPerLeb + 1
gen TrustGovR2 = -1*TrustGov + 1
gen GovDoesAllR2 = -1*GovDoesAllItCan + 1
gen CritGov2= GovPerR2 + TrustGovR2 + GovDoesAllR2 + GovCorruption
mi register passive CritGov2 GovPerR2 TrustGovR2 GovDoesAllR2 

imb Rural lnincome Age Education, tr(ArabSpring) impvar(imp)

summarize lnincome if imp==0, detail

cem Rural lnincome Age (0 27.5 37.5 47.5 57.5 67.5 77.5 110) Education (0 3.5 7), tr(ArabSpring) impvar(imp)

save LebCEM, replace

eststo Freeriding: mi estimate, post: reg Freeriding ArabSpring Education lnincome Age i.ProvinceName [aweight=cem_weights], r

eststo CritGov: mi estimate, post: reg CritGov2 ArabSpring Education lnincome Age i.ProvinceName [aweight=cem_weights], r

eststo CurrentEcon: mi estimate, post: reg CurrentEcon ArabSpring  Education lnincome Age i.ProvinceName [aweight=cem_weights], r

eststo FutureEcon: mi estimate, post: reg FutureEcon ArabSpring Education lnincome Age i.ProvinceName [aweight=cem_weights], r

coefplot (Freeriding, lab(Social Capital)) (CritGov, lab(Criticize Government)) (CurrentEcon, lab(Current Economy)) (FutureEcon, lab(Future Economy)), keep(ArabSpring) mlabel yline(0) vert format(%9.2f) graphregion(color(white)) coeflabels(ArabSpring = "Lebanon", notick ) bgcolor(white)  name(Lebanon3) saving(SBf3Leb, asis replace)

save, replace

/* Saudi Arabia -  Age (18-27, 28-37, 38-47, 48-57, 58-67, 68-77, 78+)*/
use SAForPub

gen democraticMissing = .
replace democraticMissing =   1 if DemocraticSupport==.
replace democraticMissing =   0 if DemocraticSupport != . & imp==0

gen GovPMiss = 1 if GovPer==. & imp==0
replace GovPMiss = 0 if GovPer!=. & imp==0
gen GovDMiss = 1 if GovDoesAllItCan==. & imp==0
replace GovDMiss = 0 if GovDoesAllItCan!=. & imp==0
gen TrustGMiss = 1 if  TrustGov==. & imp==0
replace TrustGMiss = 0 if  TrustGov!=. & imp==0
gen GovCorrMiss = 1 if  GovCorruption==. & imp==0
replace GovCorrMiss = 0 if   GovCorruption!=. & imp==0
gen CritMissing =  GovPMiss + GovDMiss + TrustGMiss + GovCorrMiss
mi register regular democraticMissing CritMissing GovCorrMiss TrustGMiss GovDMiss GovPMiss

gen GovPerR2 = -1*GovPer + 1
gen TrustGovR2 = -1*TrustGov + 1
gen GovDoesAllR2 = -1*GovDoesAllItCan + 1
gen CritGov2= GovPerR2 + TrustGovR2 + GovDoesAllR2 + GovCorruption
mi register passive CritGov2 GovPerR2 TrustGovR2 GovDoesAllR2 

imb Rural lnincome Age Female, tr(ArabSpring) impvar(imp)

summarize lnincome if imp==0, detail

cem Rural lnincome Age (0 27.5 37.5 47.5 57.5 67.5 77.5 110) Female, tr(ArabSpring) impvar(imp)

save SACEM

eststo Freeriding: mi estimate, post: reg Freeriding ArabSpring Rural Female lnincome Age i.ProvinceName [aweight=cem_weights], r

eststo CritGov: mi estimate, post: reg CritGov2 ArabSpring Rural Female lnincome Age i.ProvinceName [aweight=cem_weights], r

eststo CurrentEcon: mi estimate, post: reg CurrentEcon ArabSpring Rural Female lnincome Age i.ProvinceName [aweight=cem_weights], r

eststo FutureEcon: mi estimate, post: reg FutureEcon ArabSpring Rural Female lnincome Age i.ProvinceName [aweight=cem_weights], r

coefplot (Freeriding, lab(Social Capital)) (CritGov, lab(Criticize Government)) (CurrentEcon, lab(Current Economy)) (FutureEcon, lab(Future Economy)), keep(ArabSpring) mlabel yline(0) vert format(%9.2f) graphregion(color(white)) coeflabels(ArabSpring = "Saudi Arabia", notick ) bgcolor(white)  name(SA3) saving(SBf3SA, asis replace)

grc1leg Sudan3 Lebanon3 SA3, saving(SBFigure3, asis replace)
graph export SBFigure3.png, replace

eststo clear

save, replace

/* Figure 4: Greater Scrutiny or Genuine Shift in Evaluation*/
/* Sudan */

use SudanCEM

eststo DemMissing: mi estimate, post: reg democraticMissing ArabSpring Rural Female lnincome Age i.ProvinceName [aweight=cem_weights], r

eststo CritMissing: mi estimate, post: reg CritMissing ArabSpring Rural Female lnincome Age i.ProvinceName [aweight=cem_weights], r

eststo Emigrate: mi estimate, post: reg Emigrate ArabSpring Rural Female lnincome Age i.ProvinceName [aweight=cem_weights], r

eststo Democracy: mi estimate, post: reg DemocraticSupport ArabSpring Rural Female lnincome Age i.ProvinceName [aweight=cem_weights], r


coefplot (DemMissing, lab(Missing Democracy)) (CritMissing, lab(Missing Criticize Government)) (Emigrate, lab(Emigrate)) Democracy, keep(ArabSpring) mlabel yline(0) vert format(%9.2f) graphregion(color(white)) coeflabels(ArabSpring = "Sudan", notick ) ylabel(#3) bgcolor(white)  name(Sudan4, replace)

/* Lebanon */

use LebCEM

eststo DemMissing: mi estimate, post: reg democraticMissing ArabSpring Education lnincome Age i.ProvinceName [aweight=cem_weights], r

eststo CritMissing: mi estimate, post: reg CritMissing ArabSpring Rural Education lnincome Age i.ProvinceName [aweight=cem_weights], r

eststo Emigrate: mi estimate, post: reg Emigrate ArabSpring Education lnincome Age i.ProvinceName [aweight=cem_weights], r

eststo Democracy: mi estimate, post: reg DemocraticSupport ArabSpring Education Rural lnincome Age i.ProvinceName [aweight=cem_weights], r


coefplot (DemMissing, lab(Missing Democracy)) (CritMissing, lab(Missing Criticize Government)) (Emigrate, lab(Emigrate)) Democracy, keep(ArabSpring) mlabel yline(0) vert format(%9.2f) graphregion(color(white)) coeflabels(ArabSpring = "Lebanon", notick ) ylabel(#3) bgcolor(white)  name(Lebanon4, replace)

save, replace

/* Saudi Arabia */

use SACEM

eststo DemMissing: mi estimate, post: reg democraticMissing ArabSpring Rural Female lnincome Age i.ProvinceName [aweight=cem_weights], r

eststo CritMissing: mi estimate, post: reg CritMissing ArabSpring Rural Female lnincome Age i.ProvinceName [aweight=cem_weights], r

eststo Emigrate: mi estimate, post: reg Emigrate ArabSpring Rural Female lnincome Age i.ProvinceName [aweight=cem_weights], r

eststo Democracy: mi estimate, post: reg DemocraticSupport ArabSpring Rural Female lnincome Age i.ProvinceName [aweight=cem_weights], r

coefplot (DemMissing, lab(Missing Democracy)) (CritMissing, lab(Missing Criticize Government)) (Emigrate, lab(Emigrate)) Democracy, keep(ArabSpring) mlabel yline(0) vert format(%9.2f) graphregion(color(white)) coeflabels(ArabSpring = "Saudi Arabia", notick) ylabel(#3) bgcolor(white)  name(SA4, replace)

grc1leg Sudan4 Lebanon4 SA4, saving(SBFigure4, asis replace)
graph export SBFigure4.png, replace

/* Table for Figure 4 */

esttab using SBTable31.tex, star(+ 0.10 * 0.05) ci label replace booktabs mgr("Sudan" "Lebanon" "Saudi Arabia", pattern(1 0 0 0 1 0 0 0 1 0 0 0)) compress 

eststo clear

save, replace


/* Freeriding as a Mediating Variable */

use SudanCEM, clear

mi estimate (ind_eff: [Freeriding]_b[ArabSpring]*[CritGov2]_b[Freeriding]) (tot_eff: [Freeriding]_b[ArabSpring]*[CritGov2]_b[Freeriding] + [CritGov2]_b[ArabSpring]), cmdok: sureg (Freeriding ArabSpring Rural lnincome Female Age i.ProvinceName)(CritGov2 Freeriding ArabSpring Rural lnincome Female Age i.ProvinceName) [aweight=cem_weights]
mi estimate (ind_eff: [Freeriding]_b[ArabSpring]*[CurrentEcon]_b[Freeriding]) (tot_eff: [Freeriding]_b[ArabSpring]*[CurrentEcon]_b[Freeriding] + [CurrentEcon]_b[ArabSpring]), cmdok: sureg (Freeriding ArabSpring Rural lnincome Female Age i.ProvinceName)(CurrentEcon Freeriding ArabSpring Rural lnincome Female Age i.ProvinceName) [aweight=cem_weights]
mi estimate (ind_eff: [Freeriding]_b[ArabSpring]*[FutureEcon]_b[Freeriding]) (tot_eff: [Freeriding]_b[ArabSpring]*[FutureEcon]_b[Freeriding] + [FutureEcon]_b[ArabSpring]), cmdok: sureg (Freeriding ArabSpring Rural lnincome Female Age i.ProvinceName)(FutureEcon Freeriding ArabSpring Rural lnincome Female Age i.ProvinceName) [aweight=cem_weights]


/* Generate Table */

save, replace
